package com.cyberypower.sjs.jabber;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;

public class JabberEncoder {

    public static String encode(ByteBuffer bts) {
        return new BASE64Encoder().encode(bts) + "\n";
    }

    public static byte[] decode(String st) {
        try {
            return new BASE64Decoder().decodeBuffer(st.trim());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static byte[] decode(InputStream st) {
        try {
            return new BASE64Decoder().decodeBuffer(st);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
